// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   IVL_PQImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.IVL_PQ;
import com.sunwayhorizo.health.hl7.datatypes.IVL_REAL;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.datatypes.REAL;
import com.sunwayhorizo.health.hl7.datatypes.SET_PQ;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.Set;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, CSImpl, IVL_REALImpl, 
//            NullFlavorImpl, PQImpl, REALImpl, TYPEImpl

public class IVL_PQImpl extends ANYImpl
    implements IVL_PQ
{

    public static final String RCS_ID = "$Header: IVL_PQImpl.java 115.42 2005/09/16 09:23:07 amchanda noship $";
    protected REAL _low;
    protected REAL _high;
    protected BL _lowClosed;
    protected BL _highClosed;
    protected CS _unit;
    protected PQ _center;
    protected PQ _width;
    protected PQ _lowPQ;
    protected PQ _highPQ;
    protected IVL_REAL _value;
    private static final IVL_PQ nullNI = new IVL_PQImpl(CSImpl.valueOf("NI"));
    private static final IVL_PQ nullOTH = new IVL_PQImpl(CSImpl.valueOf("OTH"));
    private static final IVL_PQ nullNINF = new IVL_PQImpl(CSImpl.valueOf("NINF"));
    private static final IVL_PQ nullPINF = new IVL_PQImpl(CSImpl.valueOf("PINF"));
    private static final IVL_PQ nullUNK = new IVL_PQImpl(CSImpl.valueOf("UNK"));
    private static final IVL_PQ nullASKU = new IVL_PQImpl(CSImpl.valueOf("ASKU"));
    private static final IVL_PQ nullNAV = new IVL_PQImpl(CSImpl.valueOf("NAV"));
    private static final IVL_PQ nullMSK = new IVL_PQImpl(CSImpl.valueOf("MSK"));
    private static final IVL_PQ nullNA = new IVL_PQImpl(CSImpl.valueOf("NA"));
    private static final IVL_PQ nullNASK = new IVL_PQImpl(CSImpl.valueOf("NASK"));

    public static IVL_PQ valueOf(REAL real, BL bl, REAL real1, BL bl1, CS cs)
    {
        return new IVL_PQImpl(real, bl, real1, bl1, cs);
    }

    public static IVL_PQ valueOf(PQ pq, BL bl, PQ pq1, BL bl1)
    {
        return new IVL_PQImpl(pq, bl, pq1, bl1);
    }
    
    public static IVL_PQ valueOf(PQ pq, BL bl,  BL bl1)
    {
        return new IVL_PQImpl(pq, bl,  bl1);
    }

    public static IVL_PQ nullIVL_PQ()
    {
        return new IVL_PQImpl(null);
    }

    private IVL_PQImpl(REAL real, BL bl, REAL real1, BL bl1, CS cs)
    {
        if(real.isNull().and(real1.isNull()).isTrue())
        {
            if(real.isNull().isTrue())
                throw ANYImpl.newNullException("IVL<PQ>", "constructor", "low");
            if(real1.isNull().isTrue())
                throw ANYImpl.newNullException("IVL<PQ>", "constructor", "high");
        }
        _lowClosed = bl;
        _low = real;
        _high = real1;
        _highClosed = bl1;
        _unit = cs;
    }

    private IVL_PQImpl(PQ pq, BL bl,BL bl1)
    {
        _low = REALImpl.nullREAL(pq.nullFlavor());
        _high = pq.value();
        _unit = pq.unit();
        _lowClosed = bl;
        _highClosed = bl1;
        _lowPQ = pq;
        _highPQ = pq;
    }
    private IVL_PQImpl(PQ pq, BL bl, PQ pq1, BL bl1)
    {
        if(pq.isNull().isTrue())
        {
            if(pq1.isNull().isTrue())
                throw ANYImpl.newNullException("IVL<PQ>", "constructor", "high");
            _low = REALImpl.nullREAL(pq.nullFlavor());
            _high = pq1.value();
            _unit = pq1.unit();
        } else
        {
            if(pq1.isNull().isTrue())
            {
                _high = REALImpl.nullREAL(pq1.nullFlavor());
            } else
            {
                if(pq.unit().equal(pq1.unit()).isFalse())
                    throw ANYImpl.newIntervalException("IVL<PQ>", pq.literal().stringValue(), pq1.literal().stringValue());
                _high = pq1.value();
            }
            _low = pq.value();
            _unit = pq.unit();
        }
        _lowClosed = bl;
        _highClosed = bl1;
        _lowPQ = pq;
        _highPQ = pq1;
    }

    private IVL_PQImpl(CS cs)
    {
        super(true, cs);
        _lowPQ = PQImpl.nullPQ(NullFlavorImpl.NI);
        _highPQ = PQImpl.nullPQ(NullFlavorImpl.NI);
        _lowClosed = BLImpl.nullBL(NullFlavorImpl.NI);
        _highClosed = BLImpl.nullBL(NullFlavorImpl.NI);
        _unit = CSImpl.nullCS(NullFlavorImpl.NI);
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.IVL_PQ;
    }

    public ST literal()
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "literal");
    }

    public PQ low()
    {
        if(_lowPQ == null)
            _lowPQ = PQImpl.valueOf(_low, _unit);
        return _lowPQ;
    }

    public PQ high()
    {
        if(_highPQ == null)
            _highPQ = PQImpl.valueOf(_high, _unit);
        return _highPQ;
    }

    public BL lowClosed()
    {
        return _lowClosed;
    }

    public BL highClosed()
    {
        return _highClosed;
    }

    public PQ width()
    {
        if(isNull().isTrue())
            return PQImpl.nullPQ();
        return _width;
    }

    public IVL_REAL value()
    {
        if(isNull().isTrue())
            return IVL_REALImpl.nullIVL_REAL();
        if(_value == null)
            _value = IVL_REALImpl.valueOf(_low, _lowClosed, _high, _highClosed);
        return _value;
    }

    public CS unit()
    {
        return _unit;
    }

    public PQ center()
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "center");
    }

    public BL contains(PQ pq)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return low().lessOrEqual(pq).or(low().isNull()).and(pq.lessOrEqual(high()).or(high().isNull())).and(low().equal(pq).implies(lowClosed())).and(high().equal(pq).implies(highClosed()));
    }

    public BL isEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        if(low().isNull().or(high().isNull()).isTrue())
            return BLImpl.FALSE;
        else
            return width().isZero().and(lowClosed().and(highClosed()).not());
    }

    public BL notEmpty()
    {
        return isEmpty().not();
    }

    public BL contains(SET_PQ set_pq)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        if(set_pq instanceof IVL_PQ)
        {
            IVL_PQ ivl_pq = (IVL_PQ)set_pq;
            return contains(ivl_pq.low()).and(contains(ivl_pq.high()));
        }
        if(set_pq instanceof SET_PQ)
            return contains(((SET_PQ) (set_pq.hull())));
        else
            return BLImpl.FALSE;
    }

    public INT cardinality()
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "cardinality");
    }

    public SET_PQ union(PQ pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "union");
    }

    public SET_PQ union(SET_PQ set_pq)
    {
        if(set_pq instanceof IVL_PQ)
        {
            IVL_PQ ivl_pq = (IVL_PQ)set_pq;
            if(overlaps(ivl_pq).isTrue())
                return hull(ivl_pq);
        } else
        {
            if(contains(set_pq.hull()).isTrue())
                return this;
            if(set_pq.contains(this).isTrue())
                return set_pq;
        }
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "union");
    }

    public SET_PQ except(PQ pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "except");
    }

    public SET_PQ except(SET_PQ set_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "except");
    }

    public SET_PQ intersection(SET_PQ set_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "intersection");
    }

    public IVL_PQ intersection(IVL_PQ ivl_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "intersection");
    }

    public IVL_PQ hull(IVL_PQ ivl_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "hull");
    }

    public IVL_PQ Intersection(IVL_PQ ivl_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "Intersection");
    }

    public BL overlaps(IVL_PQ ivl_pq)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return contains(ivl_pq.low()).or(contains(ivl_pq.high())).or(ivl_pq.contains(low())).or(ivl_pq.contains(high()));
    }

    public IVL_PQ hull()
    {
        return this;
    }

    public IVL_PQ nextTo(PQ pq)
    {
        if(pq.lessOrEqual(high()).isTrue())
        {
            if(pq.equal(high()).isTrue())
            {
                if(highClosed().isFalse())
                    return this;
                else
                    return nullIVL_PQ();
            } else
            {
                return this;
            }
        } else
        {
            return nullIVL_PQ();
        }
    }

    public IVL_PQ nextAfter(PQ pq)
    {
        IVL_PQ ivl_pq = nextTo(pq);
        if(ivl_pq.isNull().isFalse() && ivl_pq.contains(pq).isFalse())
            return this;
        else
            return nullIVL_PQ();
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof IVL_PQ))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            IVL_PQ ivl_pq = (IVL_PQ)any;
            return lowClosed().equal(ivl_pq.lowClosed()).or(lowClosed().isNull().and(ivl_pq.lowClosed().isNull())).and(highClosed().equal(ivl_pq.highClosed()).or(highClosed().isNull().and(ivl_pq.highClosed().isNull()))).and(low().equal(ivl_pq.low()).or(low().isNull().and(ivl_pq.low().isNull()))).and(high().equal(ivl_pq.high()).or(high().isNull().and(ivl_pq.high().isNull())));
        }
    }

    public PQ demotion()
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "demotion");
    }

    public Set toSet()
    {
        throw ANYImpl.newUnsupportedException("IVL<PQ>", "toSet");
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLElement xmlelement = (XMLElement)xmldocument.createElement(s);
//            if(low() != null && low().isNull().isFalse())
//            {
//                XMLNode xmlnode = ((PQImpl)low()).writeXML(xmldocument, "low")[0];
//                if(!lowClosed().isNull().isTrue())
//                    ((XMLElement)xmlnode).setAttribute("inclusive", lowClosed().literal().stringValue());
//                xmlelement.appendChild(xmlnode);
//            }
//            if(high() != null && high().isNull().isFalse())
//            {
//                XMLNode xmlnode1 = ((PQImpl)high()).writeXML(xmldocument, "high")[0];
//                if(!highClosed().isNull().isTrue())
//                    ((XMLElement)xmlnode1).setAttribute("inclusive", highClosed().literal().stringValue());
//                xmlelement.appendChild(xmlnode1);
//            }
//            return (new XMLNode[] {
//                xmlelement
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

    public static IVL_PQ nullIVL_PQ(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
